package hou.river.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import hou.river.dao.RiverDao;
import hou.river.model.DepthData;

/**
 * @author houweitao
 * 2015年7月2日 上午9:30:00
 */

public class RiverDaoImpl implements RiverDao {

	@Override
	public double[] getDepth(Connection conn, DepthData place) throws SQLException {
		double depth[] = new double[12];
		
		
		for(int time = 1;time<=12;time++){
		PreparedStatement ps = conn
				.prepareStatement("SELECT * FROM river WHERE time = ? and x>? and x<? and y>? and  y<?");
		ps.setInt(1, time);
		ps.setDouble(2, place.getX()-150);
		ps.setDouble(3, place.getX()+150);
		ps.setDouble(4, place.getY()-50);
		ps.setDouble(5, place.getY()+50);
		ResultSet rs = ps.executeQuery();
		
		int pointCount=0;
		while (rs.next()) {
			System.out.println("测量次数："+time+"  坐标："+rs.getString("x")+","+rs.getString("y")+"     深度"+rs.getString("deep"));
			
			pointCount++;
			depth[time-1]=depth[time-1]+rs.getDouble("deep");
		}
		
		depth[time-1] = depth[time-1]/pointCount;
		
//		System.out.println(time +"  "+pointCount);
		
		}
		return depth;
	}

}

